from api.login import LoginAPI
# 创建测试类
class Test_login:
    uid = None
    # 前置操作
    def setup_method(self):
        # 实例化对象
        self.login = LoginAPI()
        # 将响应结果设置一个变量
        reps = self.login.get_verify_code()
        #提取uuid  设置一个类属性，使类属性的值等于uuid
        Test_login.uid = reps.json().get("uuid")
    # 后置操作
    def teardown_method(self):
        pass
    # 编写测试用例方法
    # 登陆成功
    def test01_success(self):
        json01 = {"username": "admin", "password": "HM_2023_test",
                  "code":"2", "uuid":Test_login.uid}
        rep = self.login.get_login(json01)
        # 断言响应数据中响应码是否为200
        assert 200 == rep.status_code
        # 断言响应数据中是否包含“成功”
        assert "成功" in rep.text
        # 断言响应数据中code的是是否为200
        assert 200 == rep.json().get("code")
    # 登录失败（用户名为空）
    def test02_nohave_username(self):
        json02 = {"username": "", "password": "HM_2023_test",
                  "code": "2", "uuid": Test_login.uid}
        rep01 = self.login.get_login(json02)
        assert "用户不存在/密码错误" in rep01.text
    # 登录失败（用户名未注册）
    def test03_nuzhuce_username(self):
        json03 = {"username":"fuck","password":"HM_2023_test",
                  "code":"2","uuid":Test_login.uid}
        rep03 = self.login.get_login(json03)
        assert "用户不存在/密码错误" in rep03.text













